//
//  ScanViewController.m
//  bitcoin
//
//  Created by caiyajun on 2018/5/11.
//  Copyright © 2018年 比特币. All rights reserved.
//

#import "ScanViewController.h"

@interface ScanViewController ()

@end

@implementation ScanViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"扫码添加";
    UIBarButtonItem *back = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"arrowleft-icon"] style:UIBarButtonItemStylePlain target:self action:@selector(backAction:)];
    self.navigationItem.leftBarButtonItem = back;
    
    
    //创建参数对象
    LBXScanViewStyle *style = [[LBXScanViewStyle alloc]init];
    
    //矩形区域中心上移，默认中心点为屏幕中心点
    style.centerUpOffset = 44;
    
    //扫码框周围4个角的类型,设置为外挂式
    style.photoframeAngleStyle = LBXScanViewPhotoframeAngleStyle_Outer;
    
    //扫码框周围4个角绘制的线条宽度
    style.photoframeLineW = 3;
    
    //扫码框周围4个角的宽度
    style.photoframeAngleW = 24;
    
    //扫码框周围4个角的高度
    style.photoframeAngleH = 24;
    
    //扫码框内 动画类型 --线条上下移动
    style.anmiationStyle = LBXScanViewAnimationStyle_LineMove;
    
    style.colorRetangleLine=[UIColor clearColor];
    
    style.notRecoginitonArea = [UIColor colorWithRed:0.5 green:0.5 blue:0.5 alpha:0.5];
    //扫码框周围4个角的颜色
    style.colorAngle = RGBColor(255, 182, 54);
    //线条上下移动图片
    style.animationImage = [UIImage imageNamed:@"线条"];
    //SubLBXScanViewController继承自LBXScanViewController
    self.style = style;
}
- (void)backAction:(UIBarButtonItem *)sender {
    [self.navigationController popViewControllerAnimated:YES];
}
- (void)scanResultWithArray:(NSArray<LBXScanResult*>*)array
{
    
    if (array.count < 1) {
        DLOG(@"什么都没有");
        return;
    }
    
    //经测试，可以同时识别2个二维码，不能同时识别二维码和条形码
    for (LBXScanResult *result in array) {
        
        DLOG(@"scanResult:%@",result.strScanned);
    }
    
    LBXScanResult *scanResult = array[0];
    
    NSString *strResult = scanResult.strScanned;
    
    self.scanImage = scanResult.imgScanned;
    
    if (!strResult) {
        
        DLOG(@"什么都没有");
        return;
    }
    
    NSLog(@"strResult------%@",strResult);
    if ([self.pushType isEqualToString:@"addAddress"]) {
        
        [[NSNotificationCenter defaultCenter] postNotificationName:@"scanAddressNoti" object:strResult];
    }else if ([self.pushType isEqualToString:@"drawMoney"]){
        [[NSNotificationCenter defaultCenter] postNotificationName:@"scanDrawMoneyAddressNoti" object:strResult];
    }
    [self.navigationController popViewControllerAnimated:YES];
}



@end
